/* 
 * File:   Graph.h
 * Author: chadijir
 *
 * Created on September 26, 2010, 12:53 PM
 */

#ifndef GRAPH_H
#define	GRAPH_H

#include <iostream>
#include <ostream>
#include <istream>

using namespace std;


/*
 * For graph representation we are using a matrix of unsigned chars
 *
 */
class Graph {
public:
    Graph();
    Graph(const Graph& orig);
    virtual ~Graph();

    unsigned int getMinEdgeWeight() const;
    unsigned int getRegularity() const;
    unsigned int getMaxCutWeight() const;
    unsigned int getMaxCutWeightNode() const;
    unsigned int getNodeCount() const;
    unsigned int getValue(unsigned int i, unsigned int j);
    int serialize(unsigned char * buffer, const int bufferSize);
    int deserialize(unsigned char * buffer, const int bufferSize);

    friend ostream &operator<<(ostream &out, const Graph &graph);
    friend istream &operator>>(istream &in, Graph &graph);
    
    static const unsigned int MAX_WEIGHT = 255; // max weight of any edge


private:
    void countCharacteristics(); // counts regularity, minedge, maxcut etc.
    void initMatrix(const unsigned int nc);
    unsigned int nodeCount; // number of nodes (i. e. n)
    unsigned int graphRegularity; // regularity of this graph (i.e. k)
    unsigned int minEdgeWeight; // minimum weight of any edge in given graph
    unsigned int maxCutWeight; // minimum of sum of weights of all edges inciding with any node, see overriden >> operator
    unsigned int maxCutWeightNode; // node id with max cut weight
    unsigned int getRandomWeight(); // returns random weight in <1,255> range
    unsigned int ** incidenceMatrix; // underlying array storing incidence matrix (matice sousednosti), where all edges can have some weight
};

#endif	/* GRAPH_H */

